package [package].controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import [path_1].[path_2].entity.PageResult;
import [path_1].[path_2].entity.Result;
import [path_1].[path_2].entity.StatusCode;
import [package].pojo.[Table2];
import [package].service.[Table2]Service;
import [path_1].[path_2].utils.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/[table2]")
public class [Table2]Controller {

    @Autowired
    private [Table2]Service [table2]Service;

    /**
     * 查询品牌全部数据
     *
     * @return
     */
    @GetMapping
    public Result findAll() {
        List<[Table2]> [table2]List = [table2]Service.list();
        return new Result(true, StatusCode.OK, "查询成功", [table2]List);
    }

    /***
     * 根据ID查询品牌数据
     * @param [key2]
     * @return
     */
    @GetMapping("/{[key2]}")
    public Result findById(@PathVariable [keyType] [key2]) {
        [Table2] [table2] = [table2]Service.getById([key2]);
        return new Result(true, StatusCode.OK, "查询成功", [table2]);
    }

    /***
     * 新增品牌数据
     * @param [table2]
     * @return
     */
    @PostMapping
    public Result add(@RequestBody [Table2] [table2]) {
        [table2]Service.save([table2]);
        return new Result(true, StatusCode.OK, "添加成功");
    }

    /***
     * 修改品牌数据
     * @param [table2]
     * @param [key2]
     * @return
     */
    @PutMapping(value = "/{[key2]}")
    public Result update(@RequestBody [Table2] [table2], @PathVariable [keyType] [key2]) {
        [table2]Service.updateById([table2]);
        return new Result(true, StatusCode.OK, "修改成功");
    }

    /***
     * 根据ID删除品牌数据
     * @param [key2]
     * @return
     */
    @DeleteMapping(value = "/{[key2]}")
    public Result delete(@PathVariable [keyType] [key2]) {
        [table2]Service.removeById([key2]);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    /***
     * 多条件搜索品牌数据
     * @param [table2]
     * @return
     */
    @GetMapping(value = "/search" )
    public List<[Table2]> findList([Table2] [table2]) {
        LambdaQueryWrapper<[Table2]> lqw = new LambdaQueryWrapper<>();
<条件查询.String.txt>
        return [table2]Service.list(lqw);
    }

    /***
     * 分页搜索实现
     * @param [table2]
     * @param page
     * @param size
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}")
    public Result findPage([Table2] [table2], @PathVariable int page, @PathVariable int size) {
        Page<[Table2]> pageInfo = new Page(page, size);
        LambdaQueryWrapper<[Table2]> lqw = new LambdaQueryWrapper<>();
<条件查询.String.txt>
        Page<[Table2]> [table2]Page = [table2]Service.page(pageInfo, lqw);
        PageResult pageResult = new PageResult([table2]Page.getTotal(), [table2]Page.getRecords());
        return new Result(true, StatusCode.OK, "查询成功", pageResult);
    }

}
